<html>
<head><meta charset="utf-8"><title>Slimmed Down Proposal · project-safe-transmute · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/index.html">project-safe-transmute</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Slimmed.20Down.20Proposal.html">Slimmed Down Proposal</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="188945401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Slimmed%20Down%20Proposal/near/188945401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rylev <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Slimmed.20Down.20Proposal.html#188945401">(Feb 24 2020 at 17:09)</a>:</h4>
<p>Hey all. Here's a rough draft of a slimmed down proposal similar to the one I posted last (going through a bytes intermediary). This proposal does not attempt to solve the general transmute problem (i.e., transmuting between any two compatible types), but tries to focus on the use case that I'm coming from which is efficient parsing (i.e., you have some buffer of bytes and you need to safely view types inside of that buffer). This will likely not please everyone as there are a lot of valid use cases this does not address, but I hope it seems minimal enough to be a valuable first step. Please let me know what you think: <a href="https://hackmd.io/h7a2sEioRF69wBUhsvEfwQ" target="_blank" title="https://hackmd.io/h7a2sEioRF69wBUhsvEfwQ">https://hackmd.io/h7a2sEioRF69wBUhsvEfwQ</a></p>



<a name="188951551"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Slimmed%20Down%20Proposal/near/188951551" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Slimmed.20Down.20Proposal.html#188951551">(Feb 24 2020 at 18:21)</a>:</h4>
<p>Typic is a bit of an abuse of the type system after all, and the compilation time concern can be alleviated by turning it into actual Rust code. I feel compiler subsystem that does the same thing as Typic ought to be mentioned as an alternative, for completeness.</p>



<a name="188951645"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Slimmed%20Down%20Proposal/near/188951645" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Slimmed.20Down.20Proposal.html#188951645">(Feb 24 2020 at 18:22)</a>:</h4>
<p>Also I don't see <code>bytemuck</code> mentioned as prior art. It's more minimal and focused than <code>zerocopy</code>. Was it investigated?<br>
<a href="https://docs.rs/bytemuck/1.2.0/bytemuck/" target="_blank" title="https://docs.rs/bytemuck/1.2.0/bytemuck/">https://docs.rs/bytemuck/1.2.0/bytemuck/</a></p>



<a name="188951662"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Slimmed%20Down%20Proposal/near/188951662" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Slimmed.20Down.20Proposal.html#188951662">(Feb 24 2020 at 18:23)</a>:</h4>
<p>But these are all minor nits. Thank you so much for driving this!</p>



<a name="188960261"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Slimmed%20Down%20Proposal/near/188960261" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rylev <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Slimmed.20Down.20Proposal.html#188960261">(Feb 24 2020 at 19:59)</a>:</h4>
<p>Yes, I have looked at bytemuck. I'll add that to the list, and I'll make a note about how something like typic can be built into the compiler directly</p>



<a name="188979312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Slimmed%20Down%20Proposal/near/188979312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Slimmed.20Down.20Proposal.html#188979312">(Feb 24 2020 at 23:59)</a>:</h4>
<p>Just parsing is kinda a boring sub-type of the range of casts a person can do :/</p>



<a name="188980265"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Slimmed%20Down%20Proposal/near/188980265" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Slimmed.20Down.20Proposal.html#188980265">(Feb 25 2020 at 00:14)</a>:</h4>
<p>Like to the point where bytemuck-1.0.0 literally didn't special case it at all, and simonsapin threw a PR at me to have a 1.1 with to_bytes and from_bytes and all that jazz added</p>



<a name="189206297"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Slimmed%20Down%20Proposal/near/189206297" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rylev <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Slimmed.20Down.20Proposal.html#189206297">(Feb 27 2020 at 11:46)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span>  I disagree. I've added some use cases that just bytes can get you. It covers basically 90% of the cases that people on my team need. In any case I believe that my proposal is a strict subset of the functionality to have bytemuck in the std lib. Do you agree?</p>



<a name="189222565"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Slimmed%20Down%20Proposal/near/189222565" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Slimmed.20Down.20Proposal.html#189222565">(Feb 27 2020 at 15:19)</a>:</h4>
<p>I would agree that it does cover some cases that are of use, yes.</p>
<p>However, my own experience with data casting usage is that the people kept wanting slice casting and owned casting. Once you have that, doing to and from slices of bytes is just a one liner. That's why the "to and from bytes" is the 1.1 afterthought, because you could do it for free in the 1.0 version it just wasn't entirely obvious, and essentially all that the 1.1 version did is add a function to make it more clear how to do that.</p>
<p>Also, I'm still genuinely unsure of how useful having both to_any_bytes and from_any_bytes as separate traits is. It basically means you can to_any_bytes with references to <code>char</code> and <code>bool</code>, but you can't do it with mut references, and you can't from_any_bytes them. It seems like a very small amount of utility for the complexity of having two traits.</p>



<a name="190609605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Slimmed%20Down%20Proposal/near/190609605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Slimmed.20Down.20Proposal.html#190609605">(Mar 14 2020 at 19:15)</a>:</h4>
<p>I've found <em>yet another</em> crate that provides an abstraction to reinterpret bytes as types: <a href="https://crates.io/crates/plain" target="_blank" title="https://crates.io/crates/plain">https://crates.io/crates/plain</a></p>



<a name="190609614"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Slimmed%20Down%20Proposal/near/190609614" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Slimmed.20Down.20Proposal.html#190609614">(Mar 14 2020 at 19:15)</a>:</h4>
<p>This is getting out of hand - now there are six of them!</p>



<a name="190621702"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Slimmed%20Down%20Proposal/near/190621702" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yato <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Slimmed.20Down.20Proposal.html#190621702">(Mar 15 2020 at 00:22)</a>:</h4>
<ul>
<li>plain</li>
<li>bytemuck</li>
<li>typic</li>
<li>chtrans</li>
</ul>
<p>What am I missing???</p>



<a name="190621713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Slimmed%20Down%20Proposal/near/190621713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Slimmed.20Down.20Proposal.html#190621713">(Mar 15 2020 at 00:23)</a>:</h4>
<p>zerocopy!</p>



<a name="190621754"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Slimmed%20Down%20Proposal/near/190621754" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Slimmed.20Down.20Proposal.html#190621754">(Mar 15 2020 at 00:24)</a>:</h4>
<p>And this one: <a href="https://crates.io/crates/safe-transmute" target="_blank" title="https://crates.io/crates/safe-transmute">https://crates.io/crates/safe-transmute</a></p>



<a name="190650795"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Slimmed%20Down%20Proposal/near/190650795" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Slimmed.20Down.20Proposal.html#190650795">(Mar 15 2020 at 15:01)</a>:</h4>
<p>There's also <a href="https://crates.io/crates/lazy-bytes-cast" target="_blank" title="https://crates.io/crates/lazy-bytes-cast">https://crates.io/crates/lazy-bytes-cast</a></p>



<a name="190927700"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Slimmed%20Down%20Proposal/near/190927700" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Slimmed.20Down.20Proposal.html#190927700">(Mar 18 2020 at 00:21)</a>:</h4>
<p>also <a href="https://crates.io/crates/scroll" target="_blank" title="https://crates.io/crates/scroll">https://crates.io/crates/scroll</a></p>



<a name="190927705"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Slimmed%20Down%20Proposal/near/190927705" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Slimmed.20Down.20Proposal.html#190927705">(Mar 18 2020 at 00:21)</a>:</h4>
<p>so seven</p>



<a name="190975243"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/Slimmed%20Down%20Proposal/near/190975243" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Philip Craig <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/Slimmed.20Down.20Proposal.html#190975243">(Mar 18 2020 at 12:53)</a>:</h4>
<p>scroll copies data, it doesn't transmute. However, I'm sure there's more crates than just those (e.g <a href="https://crates.io/crates/pod" target="_blank" title="https://crates.io/crates/pod">https://crates.io/crates/pod</a>, <a href="https://crates.io/crates/zero" target="_blank" title="https://crates.io/crates/zero">https://crates.io/crates/zero</a>, and more that I can't recall). Plus there's probably a few that have private implementations instead (<a href="https://github.com/gimli-rs/object/blob/master/src/pod.rs" target="_blank" title="https://github.com/gimli-rs/object/blob/master/src/pod.rs">https://github.com/gimli-rs/object/blob/master/src/pod.rs</a>).</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>